package com.test2015.Swing;

import java.awt.AWTException;
import java.awt.Dimension;
import java.awt.Point;
import java.awt.Rectangle;
import java.awt.Robot;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

import javax.imageio.ImageIO;
import javax.swing.JFrame;

public class SaveJPanelAsPic extends JFrame{
//	JPanel jpanel  = new JPanel();
//	BufferedImage image = new BufferedImage
//		(jpanel.getWidth(),jpanel.getHeight(), BufferedImage.TYPE_INT_RGB);   
//	Graphics2D g2 = image.createGraphics();   
//	jpanel.paint(g2); 
//	ImageIO.write(image, "jpeg",  new java.io.File("jpanel.jpg"));
	
	public void test () throws Exception{
		Robot rbt = new Robot();
		Point location = this.getLocation();
		int width2 = this.getWidth();
		int height2 = this.getHeight();
		
		BufferedImage createScreenCapture = 
				rbt.createScreenCapture(new Rectangle(location, new Dimension(width2,height2)));
		
		ImageIO.write(createScreenCapture, "pic format", new File(""));
	}
}
